package com.hqd.ch03.v50.boot.web.context.support;

import com.hqd.ch03.v50.io.Resource;
import com.hqd.ch03.v50.io.support.DefaultResourceLoader;
import com.hqd.ch03.v50.web.context.support.ServletContextResource;

import javax.servlet.ServletContext;

public class ServletContextResourceLoader extends DefaultResourceLoader {

    private final ServletContext servletContext;


    /**
     * Create a new ServletContextResourceLoader.
     *
     * @param servletContext the ServletContext to load resources with
     */
    public ServletContextResourceLoader(ServletContext servletContext) {
        this.servletContext = servletContext;
    }

    /**
     * This implementation supports file paths beneath the root of the web application.
     *
     * @see ServletContextResource
     */
    @Override
    protected Resource getResourceByPath(String path) {
        return new ServletContextResource(this.servletContext, path);
    }

}
